package com.team.controller;


import com.team.entity.Dept;
import com.team.service.DeptService;
import com.team.vo.DeptVo;
import com.team.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : 陈灰灰
 * @Date: 2022/10/13/19:23
 * @Description:
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 查询所有的部门
     *
     * @author 陈灰灰
     * @return {@link Result}
     */
    @RequestMapping("/deptList")
    public Result deptList(){
        return deptService.selectAllDepts();
    }

    /**
     * 科室的级联列表
     *
     * @author 太阳偷渡青山
     * @return {@link Result}
     */
    @RequestMapping("CascaderList")
    public Result CascaderList(){
        return deptService.selectAllFormatting();
    }

    /**
     * 根据管理员id查询所在部门
     * @author WHZ
     */
    @RequestMapping("/selectBydept")
    public Result selectBydept(int deptId){
        return deptService.selectBydeptId(deptId);
    }

    /**
     * 修改部门状态
     * @param deptId
     * @return
     */
    @RequestMapping("/updateStatus")
    public Result updateStatus(@RequestBody Dept deptId){
        return deptService.updatestatus(deptId);
    }

    /**
     * 添加部门
     * @param dept
     * @return
     */
    @RequestMapping("/insert")
    public Result insertAll(@RequestBody Dept dept){
        return deptService.insertAll(dept);
    }

    @RequestMapping("/selectAllDept")
    public Result selectAllDept(@RequestParam(defaultValue = "1") Integer currentPage,
                                @RequestParam(defaultValue = "5") Integer pageSize,
                                @RequestBody DeptVo deptVo){
        return deptService.selectAllDept(currentPage,pageSize,deptVo);
    }

    @RequestMapping("/deleteByPrimaryKey")
    public Result delete(@RequestBody Dept dept){
    return deptService.deleteByPrimaryKey(dept.getId());
    }
}
